<?php


namespace app\controller;


use think\captcha\Captcha;
use think\Controller;
use think\facade\Request;

class Code extends Controller
{
    //默认情况下  验证失败不会抛出异常 虚要手动设置
//    protected $failException = true;

//protected $batchValidate = true;

//方法1
     public function index(){


         $data = [
             'code' => Request::post('code')
         ];
         $flag = $this->validate($data,
             ['code|验证码' => 'require|captcha']
             );
         dump($flag);
     }

     //方法2
    public function show(){

         $config=
             [
                 //字体大小
                 'fontSize' => 30,
                 //验证码位数
                 'length' => 4,
                 //验证码杂点
                 'useNoise' => true,
                 //字体设置
                 'fontttf' => '1.ttf',
                 //启用背景
                 'useImgBg' => true,

                 //支持中文
//                 'useZh' => true
             ]
         ;
         $captcha = new Captcha($config);

//         $captcha->length = 3;
//         $captcha->useNoise = true;
//         $capycha->fontSize = 30;
         return $captcha->entry(1);
    }

    public function check(){
         $captcha = new Captcha();
         dump($captcha->check(Request::post('code'),1));
//      dump(captcha_check(Request::post('code'),1));
    }


}